﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Castle.ActiveRecord;
using SinsenWeb.Models;

namespace SinsenWeb.Controllers
{
    public class AdminController: Controller
    {
        public ActionResult CreateSchema()
        {
            ActiveRecordStarter.CreateSchema();
            CreateInstruments();
            CreateAdmin();
            
            return RedirectToAction("Done");
        }

        private void CreateInstruments()
        {
            var names = new List<string>
                            {
                                "Trompet/Kornett",
                                "Trombone",
                                "Slagverk",
                                "Saksofon",
                                "Fløyte",
                                "Waldhorn",
                                "Euphonium/Bariton",
                                "Obo",
                                "Fagott",
                                "Bassklarinett",
                                "Tuba",
                                "Klarinett",
                                "Dirigent"
                            };
           
            foreach(var instrumentName in names)
            {
                var instrument = new Instrument {Name = instrumentName};
                instrument.CreateAndFlush();
            }
        }

        private void CreateAdmin()
        {
            var m = new Member();
            m.Username = "a";
            m.Password = "a";
            m.Firstname = "Andreas";
            m.Lastname = "Knudsen";
            m.SecurityRole = 255;
            m.GeneratePasswordHash();
            m.ActiveState = 2;
            m.Instrument = Instrument.Find(1);

            m.CreateAndFlush();
            
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Done()
        {
            return View();
        }

        
    }
}
